<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let str = `1 this is for you 3
2 sds this is for you sdsd 4
6 agfgf dfdf  fgfg 5`;
      // 默认情况，正则表达式将字符串多行看作是一行
      console.log(str.match(/^\d/gm));
      console.log(str.match(/\d$/gm));
    </script>
  </body>
</html>
